package com.suep.courseScheduling.controller;

import com.suep.courseScheduling.model.CourseScheduling;
import com.suep.courseScheduling.service.CourseSchedulingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/api/coursescheduling")
public class CourseSchedulingController {
    @Autowired
    private CourseSchedulingService courseSchedulingService;

    @GetMapping("/all")
    public ResponseEntity<List<CourseScheduling>> getAllCourseSchedulings() {
        List<CourseScheduling> courseSchedulings = courseSchedulingService.findAll();
        return ResponseEntity.ok(courseSchedulings);
    }

/*    @PostMapping("/add")
    public ResponseEntity<String> addCourseScheduling(@RequestBody CourseScheduling courseScheduling) {

        int result = courseSchedulingService.addCourseScheduling(courseScheduling);
        if (result >= 0) {
            return ResponseEntity.ok("Course scheduling added successfully.");
        } else {
            return ResponseEntity.badRequest().body("Failed to add course scheduling.");
        }
    }*/

    @PostMapping("/add")
    public ResponseEntity<String> addCourseScheduling(@RequestBody CourseScheduling courseScheduling) {

        int result = courseSchedulingService.addCourseScheduling(courseScheduling);
        if (result >= 0) {
            return ResponseEntity.ok("Course scheduling added successfully.");
        } else {
            return ResponseEntity.badRequest().body("Failed to add course scheduling.");
        }
    }
    /**
     * 删除课程安排
     * @param courseScheduling 要删除的课程安排的ID
     * @return 操作结果
     */
/*    @DeleteMapping("/delete/{courseSchedulingID}")
    public ResponseEntity<String> deleteCourseScheduling(@PathVariable Integer courseSchedulingID) {
        boolean result = courseSchedulingService.deleteCourseScheduling(courseSchedulingID);
        if (result) {
            return ResponseEntity.ok("Course scheduling deleted successfully.");
        } else {
            return ResponseEntity.badRequest().body("Failed to delete course scheduling.");
        }
    }*/

    @PostMapping("/delete")
    public ResponseEntity<String> deleteCourseScheduling(@RequestBody CourseScheduling courseScheduling) {
        boolean result = courseSchedulingService.deleteCourseScheduling(courseScheduling);
        if (result) {
            return ResponseEntity.ok("Course scheduling deleted successfully.");
        } else {
            return ResponseEntity.badRequest().body("Failed to delete course scheduling.");
        }
    }

    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }
}